A good answer might be:

int count = 1;              // count is initialized
while ( count <= 3 )        // count is tested
{
  System.out.println( "count is:" + count );
  count = count + 1;        // count is changed
}
System.out.println( "Done with the loop" );      

Three Things to Coordinate

There are three things to coordinate when your program has a loop:

  1. The initial values must be set up correctly.
  2. The condition in the while statement must be correct.
  3. The change in variable(s) must be done correctly.

For example, in the above program we wanted the integers "1, 2, 3 " to be printed out. Three parts of the program had to be coordinated for this to work correctly.

QUESTION 6:

What will the program print if the initialization is changed as in the following:

int count = 0;               // count is initialized
while ( count <= 3 )         // count is tested
{
  System.out.println( "count is:" + count );
  count = count + 1;         // count is changed
}
System.out.println( "Done with the loop" );